package cn.edu.ctgu;

import java.time.Duration;
import java.time.ZonedDateTime;

public class PhoneBillCalculator {

    public double calculateCost(ZonedDateTime startTime, ZonedDateTime endTime) {
        if (endTime.isBefore(startTime)) {
            throw new IllegalArgumentException("结束时间早于开始时间");
        }

        Duration duration = Duration.between(startTime, endTime);
        long totalMinutes = duration.toMinutes();
        long seconds = duration.getSeconds() % 60;

        // 秒数向上取整
        if (seconds > 0) {
            totalMinutes++;
        }

        // 检查通话时长是否超过30小时
        if (totalMinutes > 30 * 60) {
            throw new IllegalArgumentException("通话时间超过30小时");
        }

        // 计算费用
        if (totalMinutes <= 20) {
            return totalMinutes * 0.05;
        } else {
            return 1.00 + (totalMinutes - 20) * 0.10;
        }
    }
}